<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //用法1
    let { age,name } = {name:"jack", age: 20};
    console.log(name,age);//jack 20
    // 用法2
    let width = 600;
    let height = 800;
    let depth;
    console.log(width,height);//600 800

    let size={
       width: 200,
       height: 300,
    };
    //代码块语句不允许出现在赋值语句左侧，需加小括号变成表达式
    ({ width, height} = size);
    console. log(width, height);//200 300
    //对象中不存在与变量同名的属性
    ({ width, height, depth} = size);
    console.log(width, height, depth);//200 300 undefined
    //给解构的变量设置默认值
    ({ width, height, depth= 400} = size);
    console.log(width, height, depth);//200 300 400
    //对象属性赋值给不同名变量
    let personName, name, age;
    ({name:personName,age}={name:"tom",age:20});
    console.log(personName,name,age)//tom undefined 20
    console. log(width, height);//200 300
</script>
</html>